// Manage the autocomplete box

function initSearchAutocomplete(searchFieldId) {
  // Search field for autocomplete box
  var input = document.getElementById(searchFieldId);
  
  // Create autocomplete box
  var options = {
    types: ['establishment','geocode']
  };
  var autocomplete = new google.maps.places.Autocomplete(input, options);
  autocomplete.bindTo('bounds', map); // based on the current map bounds
  
  // Event when user choose a place
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    var place = autocomplete.getPlace();
    if (place.geometry.viewport) {
      map.fitBounds(place.geometry.viewport);
    } else {
      map.setCenter(place.geometry.location);
    }
    showDraggableMarker(place.geometry.location, place.geometry.location.toString(), map);
  });
}

